const vscode = require('vscode');

// 创建输出通道
let outputChannel = null;

function getOutputChannel() {
    if (!outputChannel) {
        outputChannel = vscode.window.createOutputChannel('web-login-plugin');
    }
    return outputChannel;
}

function logToOutput(message) {
    const channel = getOutputChannel();
    const timestamp = new Date().toLocaleTimeString();
    channel.appendLine(`[${timestamp}] ${message}`);
    console.log(message); // 同时输出到控制台
}

function logError(message, error) {
    const errorMessage = error ? `${message}: ${error.message}` : message;
    logToOutput(`[ERROR] ${errorMessage}`);
    if (error && error.stack) {
        console.error(error.stack);
    }
}

function logDebug(message) {
    logToOutput(`[DEBUG] ${message}`);
}

function logInfo(message) {
    logToOutput(`[INFO] ${message}`);
}

module.exports = {
    getOutputChannel,
    logToOutput,
    logError,
    logDebug,
    logInfo
}; 